import { Component, OnInit } from '@angular/core';
import { PageService } from 'app/utils/page.service'
import { TeamManageService } from 'app/services/manage/team-manage.service'

@Component({
  selector: 'app-team-manage',
  templateUrl: './team-manage.component.html',
  styleUrls: ['./team-manage.component.less']
})
export class TeamManageComponent implements OnInit {

  private dataSet: Array<any> = []

  constructor(
    private page: PageService,
    private teamManageService: TeamManageService
  ) { }


  /**
   * 初始化
   */
  ngOnInit() {
    this.refreshData();
  }

  /**
   * 更新数据
   */
  refreshData() {
    this.teamManageService.getTeams(this.page)
      .then((data: Array<Object>) => data.map((x: any) => {
        let admin = x.get('admin')
        return {
          id: x.id,
          name: x.get('name'), // 团队名称
          admin: admin ? admin.get('realname') : '暂无',
          createAt: x.createAt
        }
      }))
      .then(data => this.dataSet = data)
  }

}
